package org.study.apitest.factory;

import org.apache.ibatis.datasource.DataSourceFactory;
import org.apache.ibatis.datasource.unpooled.UnpooledDataSource;

import javax.sql.DataSource;
import java.util.Properties;

/**
 * @program: mybatis-demo-study
 * @description:
 * @author: tmz
 * @create: 2020-08-21 13:29
 */
public class MyDataSourceFactory implements DataSourceFactory {
    private DataSource dataSource;
    @Override
    public void setProperties(Properties props) {
        props.setProperty("driver","com.mysql.cj.jdbc.Driver");
        props.setProperty("username","root");
        props.setProperty("password","Q!W@e3r4");
        props.setProperty("url","jdbc:mysql://127.0.0.1/mybatis-study");
    }

    @Override
    public DataSource getDataSource() {
        if(null==dataSource){
            dataSource = new UnpooledDataSource();
        }
        return dataSource;
    }
}
